#include "TickableManager.h"
#include "Tickable.h"

#include "Time/CPUTimeCounter.h"

void CTickableManager::Tick(float DeltaSeconds)
{   
    CODE_BLOCK_TIME_COUNT(U"心跳管理器跳动")

    //遍历所有的帧跳对象，调用Tick函数
    TVector<ITickable*> DeadTickables;

    for(auto& Tickable: AllTickables)
    {
        if(!Tickable.Value)
        {
            DeadTickables.Add(Tickable.Key);
            continue;
        }

        if(Tickable.Key->Tickable())
        {
            Tickable.Key->Tick(DeltaSeconds);
        }
    }

    //移除已经被标记为不存活的对象
    for(auto& Dead: DeadTickables)
    {
        AllTickables.Remove(Dead);
    }
}
